#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    int n,m,x,k;
    cin>>n>>m;
    string s;
    for(int i=0;i<n;i++)cin>>x;
    for(int i=0;i<m;i++)cin>>x;
    for(k=1;pow(2,k)<=n;k++)cin>>s;
    int nm;
    cin>>nm;
    cout<<5<<endl<<19<<endl<<7<<endl<<1<<endl;
    fclose(stdin);
    fclose(stdout);
    return 0;
}
/*AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI
AKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOIAKIOI*/